﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

namespace KELT.Animation.ParticleEffect
{

    public class ParticleWindAnimation : IAnimation
    {
        private DoubleAnimation cardXAnimation;
        private DoubleAnimation cardYAnimation;
        private DoubleAnimation cardZAnimation;
        int option = 0;
        int distance = 50;
        public ParticleWindAnimation()
        {
            cardYAnimation = new DoubleAnimation();
            cardXAnimation = new DoubleAnimation();
            cardZAnimation = new DoubleAnimation();

        }
        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "파티클_바람";

            Random rand = new Random();
            distance = rand.Next(-20, 20);

            cardYAnimation.AccelerationRatio = 0.5;
            cardYAnimation.Duration = new Duration(TimeSpan.FromSeconds(endTime - startTime));
            cardYAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            cardYAnimation.From = obj.getPosition().Y;
            cardYAnimation.To = obj.getPosition().Y + distance;
            Storyboard.SetTargetProperty(cardYAnimation, new PropertyPath(TranslateTransform3D.OffsetYProperty));

            Storyboard.SetTargetName(cardYAnimation, AnimationInfo.ANIMATION_TRANSLATE + obj.getIndexNumber());
            myStoryboard.Children.Add(cardYAnimation);


            cardXAnimation.AccelerationRatio = 0.5;
            cardXAnimation.AccelerationRatio = 0.5;
            cardXAnimation.DecelerationRatio = 0.5;

            cardXAnimation.Duration = new Duration(TimeSpan.FromSeconds(endTime - startTime));
            cardXAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            distance = 50; ;
            Thread.Sleep(5);
            cardXAnimation.From = obj.getPosition().X;
            cardXAnimation.To = obj.getPosition().X + distance;
            Storyboard.SetTargetProperty(cardXAnimation, new PropertyPath(TranslateTransform3D.OffsetXProperty));

            Storyboard.SetTargetName(cardXAnimation, AnimationInfo.ANIMATION_TRANSLATE + obj.getIndexNumber());
            myStoryboard.Children.Add(cardXAnimation);


            cardZAnimation.AccelerationRatio = 0.5;
            cardZAnimation.AccelerationRatio = 0.5;
            cardZAnimation.DecelerationRatio = 0.5;

            cardZAnimation.Duration = new Duration(TimeSpan.FromSeconds(endTime - startTime));
            cardZAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

            distance = 10;
            Thread.Sleep(5);
            cardZAnimation.From = obj.getPosition().Z;
            cardZAnimation.To = obj.getPosition().Z + distance;
            Storyboard.SetTargetProperty(cardZAnimation, new PropertyPath(TranslateTransform3D.OffsetZProperty));

            Storyboard.SetTargetName(cardZAnimation, AnimationInfo.ANIMATION_TRANSLATE + obj.getIndexNumber());
            myStoryboard.Children.Add(cardZAnimation);


        }

        public void setOption(int count)
        {
            option = count;
        }
        public override void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(cardXAnimation);
            myStoryboard.Children.Remove(cardYAnimation);
            myStoryboard.Children.Remove(cardZAnimation);
        }

        public override void changeAnimation(Storyboard myStoryboard)
        {
        }
    }
}
